package com.dds.web.controller.union;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.dds.common.core.domain.model.LoginUser;
import com.dds.common.utils.ServletUtils;
import com.dds.framework.web.service.TokenService;
import com.dds.system.service.union.IUnionShopSubsidyPeriodService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.dds.common.annotation.Log;
import com.dds.common.core.controller.BaseController;
import com.dds.common.core.domain.AjaxResult;
import com.dds.common.enums.BusinessType;
import com.dds.system.domain.union.UnionShopSubsidy;
import com.dds.system.service.union.IUnionShopSubsidyService;
import com.dds.common.utils.poi.ExcelUtil;
import com.dds.common.core.page.TableDataInfo;

/**
 * 商家特殊补贴Controller
 * 
 * @author gaolianjie
 * @date 2021-04-16
 */
@RestController
@RequestMapping("/union/subsidy")
public class UnionShopSubsidyController extends BaseController
{
    @Autowired
    private IUnionShopSubsidyService unionShopSubsidyService;

    @Autowired
    private IUnionShopSubsidyPeriodService unionShopSubsidyPeriodService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询商家特殊补贴列表
     */
    @PreAuthorize("@ss.hasPermi('union:subsidy:list')")
    @GetMapping("/list")
    public TableDataInfo list(
            @RequestParam(name = "shopName", required = false) String shopName
    )
    {
        startPage();
        List<Map<String, Object>> list = unionShopSubsidyService.selectUnionShopSubsidyList(shopName);
        return getDataTable(list);
    }

    /**
     * 获取商家特殊补贴详细信息
     */
    @PreAuthorize("@ss.hasPermi('union:subsidy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(unionShopSubsidyService.selectUnionShopSubsidyById(id));
    }

    /**
     * 新增商家特殊补贴
     */
    @PreAuthorize("@ss.hasPermi('union:subsidy:add')")
    @Log(title = "商家特殊补贴", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Map<String, Object> params)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();

        return toAjax(unionShopSubsidyService.insertUnionShopSubsidy(params, userId));
    }

    /**
     * 修改商家特殊补贴
     */
    @PreAuthorize("@ss.hasPermi('union:subsidy:edit')")
    @Log(title = "商家特殊补贴", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Map<String, Object> params)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());

        return toAjax(unionShopSubsidyService.updateUnionShopSubsidy(params, loginUser.getUser().getUserId()));
    }

    /**
     * 删除商家特殊补贴
     */
    @PreAuthorize("@ss.hasPermi('union:subsidy:remove')")
    @Log(title = "商家特殊补贴", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(unionShopSubsidyService.deleteUnionShopSubsidyByIds(ids));
    }

    @GetMapping("/period/{shopId}")
    public TableDataInfo periodList(@PathVariable String shopId) {
        return getDataTable(unionShopSubsidyPeriodService.selectUnionShopSubsidyPeriodList(shopId));
    }
}
